Skip to content

🐛Use k8s.io/apimachinery/pkg/util/json to unmarshal in fakeclient #3208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

troy0820
Copy link
Member

@troy0820 troy0820 commented May 7, 2025

This will use k8s.io/apimachinery/pkg/util/json which calls sigs.k8s.io/json to UnmarshalWithCaseSensitivePreserveInts in the fakeclient.

Resolves #3207

NOTE: https://pkg.go.dev/sigs.k8s.io/json#UnmarshalCaseSensitivePreserveInts

UnmarshalCaseSensitivePreserveInts parses the JSON-encoded data and stores the result in the value pointed to by v.

UnmarshalCaseSensitivePreserveInts matches the behavior of encoding/json#Unmarshal, with the following changes:

When unmarshaling into a struct, JSON keys must case-sensitively match json tag names (for tagged struct fields) or struct field names (for untagged struct fields), or they are treated as unknown fields and discarded.

When unmarshaling a number into an interface value, it is unmarshaled as an int64 if the JSON data does not contain a "." character and parses as an integer successfully and does not overflow int64. Otherwise, the number is unmarshaled as a float64.

If a syntax error is returned, it will not be of type encoding/json#SyntaxError, but will be recognizeable by this package's IsSyntaxError() function

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 7, 2025
@k8s-ci-robot k8s-ci-robot requested review from FillZpp and inteon May 7, 2025 15:30
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 7, 2025
@troy0820 troy0820 force-pushed the troy0820/api-machinery-marshal branch from 43929d1 to dde4486 Compare May 7, 2025 15:32
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 8, 2025
@troy0820 troy0820 force-pushed the troy0820/api-machinery-marshal branch from 73e4dac to a4ac626 Compare May 8, 2025 15:23
@troy0820 troy0820 changed the title 🐛Use sigs.k8s.io/json to unmarshal in fakeclient 🐛Use k8s.io/apimachinery/pkg/util/json to unmarshal in fakeclient May 8, 2025
@troy0820
Copy link
Member Author

troy0820 commented May 9, 2025

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 9, 2025
@sbueringer
Copy link
Member

@troy0820 All good from my side. Do you have time to add a unit test?

It would be nice to get this into CR v0.21

@troy0820
Copy link
Member Author

@troy0820 All good from my side. Do you have time to add a unit test?

Yes, I am going to work on this today.

@sbueringer
Copy link
Member

Thank you very much!

@troy0820 troy0820 force-pushed the troy0820/api-machinery-marshal branch from a4ac626 to 4e708fe Compare May 12, 2025 16:25
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 12, 2025
@sbueringer
Copy link
Member

Strange: #3208 (comment)
Probably I missed something :)

@troy0820 troy0820 force-pushed the troy0820/api-machinery-marshal branch from 4e708fe to 643737a Compare May 12, 2025 17:42
@sbueringer
Copy link
Member

sbueringer commented May 12, 2025

@troy0820 One thing I forgot. Please squash the commits and update the one message according to the changes

@troy0820 troy0820 force-pushed the troy0820/api-machinery-marshal branch 3 times, most recently from fbc3f25 to bbb1e12 Compare May 13, 2025 13:17
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 13, 2025
@troy0820 troy0820 force-pushed the troy0820/api-machinery-marshal branch from bbb1e12 to d9721fa Compare May 13, 2025 14:45
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last nits from my side. Thx everyone for working on this!

@troy0820 troy0820 force-pushed the troy0820/api-machinery-marshal branch from d9721fa to b3278df Compare May 13, 2025 15:03
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 13, 2025
@sbueringer
Copy link
Member

Thx everyone!

/lgtm
/hold cancel

/assign @alvaroaleman

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 13, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 13, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: a2d28d8c5336a2b472ada822fb0ce8df2224d73c

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, troy0820

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 13, 2025
@k8s-ci-robot k8s-ci-robot merged commit 9b5f6a7 into kubernetes-sigs:main May 13, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FakeClient: use apiMachinery json when serializing/deserializing
6 participants